package org.example.service.impl;

import jakarta.annotation.Resource;
import org.example.dao.address.AddressMapper;
import org.example.entity.Address;
import org.example.service.AddressService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressServiceImpl implements AddressService {

    @Resource
    private AddressMapper addressMapper;
    /**
     * 新增收货地址
     * */
    @Override
    public boolean addAddress(Address address) {
        if (address.getStatus().equals("0"))
            return addressMapper.addAddress(address);
        addressMapper.setAddressStatusToZero(address.getOpenId());
        return addressMapper.addAddress(address);
    }

    /**
     * 删除收货地址
     * */
    @Override
    public boolean deleteAddress(Integer addressId) {
        return addressMapper.deleteAddress(addressId);
    }
    /**
     * 更新收货地址
     * */
    @Override
    public boolean updateAddress(Address address) {
        if (address.getStatus().equals("0"))
            return addressMapper.updateAddress(address);
        addressMapper.setAddressStatusToZero(address.getOpenId());
        return addressMapper.updateAddress(address);
    }

    /**
     * 获取用户的收货地址列表*/

    @Override
    public List<Address> list(String openId) {
        return addressMapper.list(openId);
    }


    public Address getDefaultAddress(String openId) {
        return addressMapper.getDefaultAddress(openId);
    }
}
